package com.hmall.cart.listener;

import com.hmall.api.client.CartClient;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
@RequiredArgsConstructor
public class cartListener {

        private final CartClient cartClient;

        @RabbitListener(bindings = @QueueBinding(
                value = @Queue(name = "cart.clear.queue",durable = "true"),
                exchange = @Exchange(name = "trade.topic",type = ExchangeTypes.TOPIC),
                key ="order.create"
        )

        )
        public void listenerOrderCreate(Collection<Long> itemids)
        {
            cartClient.deleteCartItemByIds(itemids);
        }



}
